from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
#chromedriver版本为137版本
driver_path = "D:\\pycharm\\PM_test\\chromedriver.exe"

service = Service(driver_path)
options = Options()
browser = webdriver.Chrome(service=service, options=options)
browser.maximize_window()
wait = WebDriverWait(browser, 10)

def login():
    browser.get("http://146.56.217.9:9131")
    browser.find_element(By.ID, "username").send_keys("admin_9131")
    browser.find_element(By.ID, "password").send_keys("admin")
    browser.find_element(By.CLASS_NAME, "button").click()
def group_list_search():
    # 点击菜单进入新建组界面
    browser.find_element(By.CSS_SELECTOR, ".menu_titre > a[title='用户和组']").click()
    browser.find_element(By.CSS_SELECTOR, ".menu_contenu_user_group_list > a[title='组清单']").click()
    #选择框
    browser.find_element(By.CSS_SELECTOR,".div-table-responsive tr:nth-child(2)>td:nth-child(6)>input").click()
    #全选框
    browser.find_element(By.ID,"checkforselects").click()
    #功能选择框
    browser.find_element(By.CSS_SELECTOR,"select#massaction>option:nth-child(2)").click()
    #确认按钮
    browser.find_element(By.NAME,"confirmmassaction").click()
    #弹出的框child为1时，选是，2为否
    sleep(2)
    browser.find_element(By.CSS_SELECTOR,"select#confirm>option:nth-child(1)").click()
    #验证（确认删除）
    browser.find_element(By.CSS_SELECTOR,'input.button.valignmiddle.confirmvalidatebutton.small[type="submit"][value="验证"]').click()
if __name__ == '__main__':
    try:
        login()
        group_list_search()
    except Exception as e:
        print(e)
    finally:
        sleep(1)
        browser.quit()